package com.yami.shop.sys.platform.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.sys.common.model.SysLog;
import com.yami.shop.sys.common.service.SysLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;




/**
 * 系统日志
 * @author lgh
 */
@Tag(name = "系统日志")
@RestController
@RequestMapping("/sys/log")
public class SysLogController {
    @Autowired
    private SysLogService sysLogService;

    @GetMapping("/page")
    @Operation(summary =  "列表", description = "列表")
    @PreAuthorize("@pms.hasPermission('sys:log:page')")
    public ServerResponseEntity<IPage<SysLog>> page(@ParameterObject SysLog sysLog, PageParam<SysLog> page){
        IPage<SysLog> sysLogs = sysLogService.page(page,
                new LambdaQueryWrapper<SysLog>()
                        .like(StrUtil.isNotBlank(sysLog.getUsername()),SysLog::getUsername, sysLog.getUsername())
                        .like(StrUtil.isNotBlank(sysLog.getOperation()), SysLog::getOperation,sysLog.getOperation())
                        .orderByDesc(SysLog::getId)

        );
        return ServerResponseEntity.success(sysLogs);
    }

}
